 
import * as Koa from 'koa';
import * as cors from 'koa-cors'   // 解决跨域
// import {koaBody} from 'koa-body'
import {initRoute} from "./route/index"
import {initModules} from "./module/initModule"
import { serverCfg } from './serverCfg'
import * as kstatic from "koa-static";
import * as path from "path"
import { ENV } from './cofing';


// async function startup(){
    const app = new Koa();

    let cfg = serverCfg[ENV];
        
    app.use(cors());

    initModules()
    
    app.use(kstatic(path.join(__dirname, "../public")));
    // 将路由器添加到我们的应用程序中
    
    initRoute(app)

    // app.use(koaBody());
     
    app.use((ctx)=>{
        console.log(ctx.query)
    })

    app.use(async ctx => {
        if (ctx.status === 404) {
            ctx.body = '404 - Not Found';
            ctx.status = 404;
        }
    });

    app.listen(cfg.port);
    
    console.log('Server running on port '+cfg.port);
// }

// startup();